﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using OilRigSumoWrestlers.KeyBindings;
using OilRigSumoWrestlers.Scenes.Menu;
using RaptorEngine;
using RaptorEngine.Components;
using RaptorEngine.Managers;

namespace OilRigSumoWrestlers.Controllables.Controllers
{
    public class SplashScreenController : Controllable
    {
        public SplashScreenController(Entity entity) : base(entity)
        {
        }
        public override void Update(GameTime time)
        {
            if (GameEngine.Instance.Input.IsPressed(Keys.Enter))
            {
                new PlayerKeyboardBindings(LogicalPlayerIndex.One).ActivateBindings();
                GoForwards();
            }
            else if (GameEngine.Instance.Input.IsPressed(Keys.Escape) || GameEngine.Instance.Input.IsPressed(Buttons.B, LogicalPlayerIndex.Any))
            {
                GameEngine.Instance.Exit();
            }
            else
            {
                for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
                {
                    if (!GameEngine.Instance.Input.IsPlayerBound(LogicalPlayerIndex.One, i)
                    && (GameEngine.Instance.Input.IsPressed(Buttons.A, i)
                    || GameEngine.Instance.Input.IsPressed(Buttons.Start, i)))
                    {
                        GameEngine.Instance.Input.SetLogicalPlayer(LogicalPlayerIndex.One, i);
                        SetGamepadBindings();
                    }
                }
            }
        }

        private void SetGamepadBindings()
        {
            new PlayerGamepadBindings(LogicalPlayerIndex.One).ActivateBindings();
            GoForwards();
        }


        protected void GoForwards()
        {
            GameEngine.Instance.Scene.HideCurrentScene();
            GameEngine.Instance.Scene.StopCurrentScene();
            GameEngine.Instance.Scene.PushScene(new MainMenu());
            GameEngine.Instance.Scene.StartCurrentScene();
            GameEngine.Instance.Scene.ShowCurrentScene();
            GameEngine.Instance.Audio.PlaySound("menu_forward", .5f);
        }
    }
}
